import { getComplaint, agree, disagree } from '@/api/complaint'
import type { Complaint } from '@/api/complaint/type'
import type { BaseResponse } from '@/api/base'
import { toast } from '@/utils/common'

const loadDetail = async (item: Complaint) => {
  try {
    const res: BaseResponse = await getComplaint(item.id)
    item.reject = res.data.reject
    item.agree = res.data.agree
    item.comment = res.data.comment
    item.agreeCount = res.data.agreeCount
    item.commentCount = res.data.commentCount
    item.rejectCount = res.data.rejectCount
  } catch (error) {
    toast(error.tips)
  }
}
export const optAgree = async (item: Complaint) => {
  try {
    await agree(item.id)
    loadDetail(item)
  } catch (error) {
    toast(error.tips)
  }
}
export const optDisAgree = async (item: Complaint) => {
  try {
    await disagree(item.id)
    loadDetail(item)
  } catch (error) {
    toast(error.tips)
  }
}

export const getStatusText = (status: number) => {
  const map = {
    0: '已撤销',
    1: '待发布',
    2: '已发布'
  }
  return map[status]
}
export const getStatusColor = (status: number) => {
  const map = {
    0: 'error',
    1: 'primary',
    2: 'success'
  }
  return map[status]
}